<?php

namespace App\Http\Controllers\Backend;

use App\Admin;
use Illuminate\Http\Request;

use App\Http\Requests;
use \Session;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

class LoginController extends Controller
{

    /**
     * 视图
     */
    public function index()
    {
        if(Session::has('admin')){
           return redirect('/backend/index');
        }
        return view('backend.login.index');
    }

    /**
     * 登陆
     */
    public function doLogin()
    {
        $username = Input::get('username');
        $password = Input::get('password');
        $admin = Admin::where('username', '=', $username)->first();
        if (count($admin) == 0) {
            $data['type']='w';
            $data['message']='用户不存在';
            return redirect()->back()->with('message', $data);
        }
//        if (!\Hash::check($password, $admin->password)) {
//            $data['type']='w';
//            $data['message']='密码错误';
//            return redirect()->back()->with('message', $data);
//        }
        Session::set('admin',$admin);
        return redirect('backend/index');
    }

    public function logout(){
        Session::clear();
        return redirect('backend/login');
    }

}
